package pruebas;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.UIManager;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JTextArea;
import java.awt.GridLayout;
import javax.swing.JButton;

import MaquinaVirtual.Error_MV;
import MaquinaVirtual.MaquinaPila;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import javax.swing.JScrollPane;
import javax.swing.border.EtchedBorder;
import javax.swing.table.DefaultTableModel;



public class PruebaMP extends JFrame{
	
	public MaquinaPila MP;
	PruebaMP esta;
	public JTextArea textArea;
	public JTextArea textArea_1;
	private JTable TMemoria;
	JScrollPane scrollPane;
	String[] cabMem= {"Direcci\u00F3n", "Contenido"};
	int x;
	
	public static void main(String[] args) {
	
		PruebaMP frame = new PruebaMP();
				
		frame.setVisible(true);
		frame.setSize(1200,600);
		frame.setLocationRelativeTo(null);
				
	}
	public PruebaMP() {
		x=0;
		getContentPane().setLayout(null);
		esta=this;
		textArea = new JTextArea();
		MP= new MaquinaPila();
		textArea.setBounds(10, 36, 139, 358);
		getContentPane().add(textArea);
		
		textArea_1 = new JTextArea();
		textArea_1.setBounds(159, 36, 139, 358);
		getContentPane().add(textArea_1);
		
		JLabel lblCodigoPila = new JLabel("Codigo Pila:");
		lblCodigoPila.setBounds(10, 11, 72, 14);
		getContentPane().add(lblCodigoPila);
		
		JLabel lblMaquinaPila = new JLabel("Maquina Pila:");
		lblMaquinaPila.setBounds(159, 11, 82, 14);
		getContentPane().add(lblMaquinaPila);
		
		JLabel lblConsola = new JLabel("Consola:");
		lblConsola.setBounds(308, 11, 46, 14);
		getContentPane().add(lblConsola);
		JButton btnProbar = new JButton("Probar");
		btnProbar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				try {
					MP.ejecutarPrueba(x,textArea.getText(),esta);
					x++;
			} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
		btnProbar.setBounds(98, 405, 89, 23);
		getContentPane().add(btnProbar);
		
		scrollPane = new JScrollPane();
		scrollPane.setBounds(308, 36, 417, 192);
		getContentPane().add(scrollPane);
		
		TMemoria = new JTable();
		scrollPane.setViewportView(TMemoria);
		TMemoria.setName("Tabla");
		TMemoria.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		TMemoria.setModel(new DefaultTableModel(
			new Object[][] {},
			new String[] {"Direcci\u00F3n", "Contenido"}
		) {
			Class[] columnTypes = new Class[] {
				Integer.class, String.class
			};
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
		});
	}
	public void setTexPila(String pila){
		this.textArea_1.setText(pila);
	}
	public void setTexMem(String[][] str){
		this.scrollPane.remove(TMemoria);
		TMemoria = new JTable(str,cabMem);
		this.scrollPane.setViewportView(TMemoria);
	}
}
